package cn.wl.hrm.web.controller;

import cn.wl.hrm.dto.SendSmsDto;
import cn.wl.hrm.service.VerifyCodeService;
import cn.wl.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;

    //获取图片验证码
    @RequestMapping(value = "/verifycode/imageCode/{imageKey}",method = RequestMethod.POST)
    public AjaxResult createImageCode(@PathVariable("imageKey") String imageKey){
        try {
            String resultObject = verifyCodeService.createImageCode(imageKey);
            return AjaxResult.me().setResultObj(resultObject);
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }

    //获取短信验证码
    @RequestMapping(value = "/verifycode/sendSmsCode",method = RequestMethod.POST)
    public AjaxResult sendSmsCode(@RequestBody SendSmsDto sendSmsDto){
        try {
            verifyCodeService.sendSmsCode(sendSmsDto);
            return AjaxResult.me();
        }catch (Exception e){
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }


}
